home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9104.zip / MOUSE4.C < prev    next >
Text File  |  1991-03-05  |  3KB  |  102 lines

  1. /************************************************************************
  2. * MOUSE4.C -- demonstrate how to alter the graphics mouse cursor.         *
  3. * This program changes cursor styles, depending on which side of the     *
  4. * screen the cursor is.                                                 *
  5. *                                                                         *
  6. * To compile: "cl mouse4.c /link graphics"                                 *
  7. ************************************************************************/
  8.  
  9. #include <dos.h>    /* int86(), union REGS                                */
  10. #include <conio.h>    /* kbhit()                                            */
  11. #include <graph.h>    /* _DEFAULTMODE, _ellipse(), _GFILLINTERIOR,        */
  12.                     /* _MRES16COLOR, _setcolor(), _setvideomode()        */
  13. #include <stdio.h>    /* printf()                                            */
  14. #include <stdlib.h>/* exit(), EXIT_FAILURE, EXIT_SUCCESS                */
  15.  
  16. void main(void)
  17.     {
  18.     union REGS in_regs, out_regs;
  19.  
  20.     /* The right hand mouse cursor is a block */
  21.     unsigned right_mouse_cursor[] =
  22.         {
  23.         /* Screen mask */
  24.         0xffff,        0xffff,        0xffff,        0xffff,
  25.         0xffff,        0xffff,        0xffff,        0xffff,
  26.         0xffff,        0xffff,        0xffff,        0xffff,
  27.         0xffff,        0xffff,        0xffff,        0xffff,
  28.         /* Cursor mask */
  29.         0xffff,        0xffff,        0xffff,        0xffff,
  30.         0xffff,        0xffff,        0xffff,        0xffff,
  31.         0xffff,        0xffff,        0xffff,        0xffff,
  32.         0xffff,        0xffff,        0xffff,        0xffff,
  33.         };
  34.     unsigned char NewFillMask[]=
  35.         { 0x00, 0x55, 0x00, 0xaa, 0x00, 0x55, 0x00, 0xaa };
  36.  
  37.     /* The left side mouse cursor is a crosshair */
  38.     unsigned left_mouse_cursor[] = 
  39.         {
  40.         /* Screen mask */
  41.         0xfcff,        0xfcff,        0xfcff,        0xfcff,
  42.         0xfcff,        0xfcff,        0xfcff,        0x0003,
  43.         0x0003,        0xfcff,        0xfcff,        0xfcff,
  44.         0xfcff,        0xfcff,        0xfcff,        0xfcff,
  45.         /* Cursor mask */
  46.         0x0300,        0x0300,        0x0300,        0x0300,
  47.         0x0300,        0x0300,        0x0300,        0xfcfc,
  48.         0xfcfc,        0x0300,        0x0300,        0x0300,
  49.         0x0300,        0x0300,        0x0300,        0x0300,
  50.         };
  51.  
  52.     /* Set the CRT to four color mode, and draw a cyan ellipse    */
  53.     _setvideomode(_MRES4COLOR);
  54.     _selectpalette(1);
  55.     _setcolor(1);
  56.     _ellipse(_GFILLINTERIOR, 25, 25, 180, 100);
  57.     _setcolor(2);
  58.     _setfillmask(NewFillMask);
  59.     _rectangle(_GBORDER, 100, 110, 200, 190);
  60.     _rectangle(_GFILLINTERIOR, 100, 110, 200, 190);
  61.  
  62.     /* Initialize the mouse */
  63.     in_regs.x.ax = 0;
  64.     int86(0x33, &in_regs, &out_regs);
  65.     if (!out_regs.x.ax)
  66.         {
  67.         printf("ERROR - Mouse could not be initialized.\n");
  68.         exit(EXIT_FAILURE);
  69.         }
  70.     printf("Mouse initialized.\n");
  71.  
  72.     /* Display the mouse cursor */
  73.     in_regs.x.ax = 1;
  74.     int86(0x33, &in_regs, &out_regs);
  75.  
  76.     printf("Type a 'q' to quit.");
  77.     while ( !kbhit() )
  78.         {
  79.         /* Get the current mouse information */
  80.         in_regs.x.ax = 3;
  81.         int86(0x33, &in_regs, &out_regs);
  82.  
  83.         /* Set the appropriate mouse cursor */
  84.         if (out_regs.x.cx < 320)
  85.             /* If mouse is on left half of screen use left mouse cursor    */
  86.             in_regs.x.dx = (int) left_mouse_cursor;
  87.         else
  88.             /* Otherwise, use the right side mouse cursor */
  89.             in_regs.x.dx = (int) right_mouse_cursor;
  90.         in_regs.x.bx = 0;
  91.         in_regs.x.cx = 0;
  92.         in_regs.x.ax = 9;
  93.         int86(0x33, &in_regs, &out_regs);
  94.     }
  95.  
  96.     /* Clear the keyboard buffer, reset the display, and quit    */
  97.     while ( kbhit() )
  98.         getch();
  99.     _setvideomode(_DEFAULTMODE);
  100.     exit(EXIT_SUCCESS);
  101.     }
  102.